package org.vergil.core.thread.producerconsumer;

import java.util.Random;

/**
 * Created by vergil on 17-3-18.
 */
public class Producer implements Runnable {

    private Business business;

    Producer(Business business) {
        this.business = business;
    }

    @Override
    public void run() {
        while (true) {
            Random random = new Random();
            int num = random.nextInt(10);
            try {
                synchronized (this){
                    business.push(num,"book");
                }
                System.out.println(Thread.currentThread().getName() + " product:" + num + ",name: " + "book");
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
    }
}
}
